/*
  This software is copyright 2009 Matthew Wilson matthew@wilson.org
  and available under the Artistic License 2 ("AL2") as documented at
  http://jsmeta.googlecode.com
*/

var TestMode = true;

function runTests() {
  var startTime = (new Date()).getTime();
  
  traceOn = typeof(callTraceNodeAdd)!='undefined';
  
  traceOn = false;
  
  var result = '';
  
  //if (typeof(console)!='undefined' && console.profile) { console.profile() }
  
  var tests =
  [ { input: "ii"
    , grammar: function(l) {
        return l.any('ii');
      }
    , result: "ii"}
  ];
  
 //try {
  
  var r;
  var maxTests = 999;
  var testsTried = 0;
  
  for (var i = 0; i < tests.length && i <= maxTests; i++) {
    if (tests[i].skip || tests[i].todo) continue;
    testsTried++;
    r = Module.Parse(tests[i].grammar, tests[i].input);
    if (r.result!=tests[i].result.toString() && !traceOn && !inConsole) {
      traceOn = true;
      r = Module.Parse(tests[i].grammar, tests[i].input);
      traceOn = false;
      result += (inConsole ? '\n   ' : '<br />&nbsp&nbsp;&nbsp;') + (r.result==tests[i].result.toString() ? 'ok '+i+' ...'+r.duration : 'nok '+i + ': '+[r.grammar, r.result, tests[i].result.toString()]);
      break;
    } else {
      result += (inConsole ? '\n   ' : '<br />&nbsp&nbsp;&nbsp;') + (r.result==tests[i].result.toString() ? 'ok '+i+' ...'+r.duration : 'nok '+i + ': '+[r.grammar, r.result, tests[i].result.toString(), r.duration]);
    }
  }
  
  result += (inConsole ? '\n\n\t\t' : '<br /><br />&nbsp&nbsp;&nbsp;') + ' Test Duration: ' + ((new Date()).getTime() - startTime) + ' ms   Tests Tried: ' + testsTried + ' of ' + tests.length;
  
  //} catch(e) { result += (inConsole ? '\n   ' : '<br />&nbsp&nbsp;&nbsp;') + e; }
  
  //if (typeof(console)!='undefined' && console.profile) { console.profileEnd() }
  return result;
};
























